using System;
using System.Collections.Generic;
using System.Text;
using emp.Model.SysManage;
using emp.BLL.SysManage;
using emp.Utility;
using System.Web;

namespace emp.ProcessFlow.SysManage
{
    public class PrivlKeyController
    {

        #region PrivlKeyController Members

        private const string URL_DEFAULT = "key_list.aspx";

        public PrivlKeyController()
        {
        }

        public bool Create(PrivilegeKeyInfo newKeyInfo)
        {
            try
            {
                PrivilegeKey myPrivlKey = new PrivilegeKey();
                if (myPrivlKey.Insert(newKeyInfo) < 1)
                {
                    return false;
                }
                
            }
            catch(Exception error)
            {
                string sMethod = "emp.ProcessFlow.SysManage.PrivlKeyController.Create(PrivilegeKeyInfo newKeyInfo)";
                EventsLog.WriteLog(error,sMethod);
                return false;
            }

            HttpContext.Current.Response.Redirect(URL_DEFAULT, true);
            return true;
        }
        
        public bool Update(PrivilegeKeyInfo updatedKeyInfo,string sCurPage)
        {
            try
            {
                PrivilegeKey myPrivlKey = new PrivilegeKey();
                if (myPrivlKey.Update(updatedKeyInfo) < 1)
                {
                    return false;
                }
            }
            catch (Exception error)
            {
                string sMethod = "emp.ProcessFlow.SysManage.PrivlKeyController.Update((PrivilegeKeyInfo updatedKeyInfo,string sCurPage))";
                EventsLog.WriteLog(error, sMethod);
                return false;
            }

            HttpContext.Current.Response.Redirect(URL_DEFAULT + "?page=" + sCurPage, true);
            return true;
        }

        public bool Delete(int iNodeID, string sCurPage)
        {
            try
            {
                PrivilegeKey myPrivlKey = new PrivilegeKey();
                if (myPrivlKey.Delete(iNodeID) < 1)
                {
                    return false;
                }
            }
            catch (Exception error)
            {
                string sMethod = "emp.ProcessFlow.SysManage.PrivlKeyController.Delete(int iNodeID, string sCurPage)";
                EventsLog.WriteLog(error, sMethod);
                return false;
            }

            HttpContext.Current.Response.Redirect(URL_DEFAULT + "?page=" + sCurPage, true);
            return true;
        }
        
        #endregion
    }
}
